package org.metasketch.simulator.runtime;

import java.util.List;

import org.metasketch.simulator.tools.generic.Variable;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;

public class ExpressionEngine {

	public static Long getLong(String arrivalExpression) {

		Long timeInSeconds = null;

		String time = arrivalExpression;

		if (time.endsWith("h")) {
			time = time.substring(0, time.length() - 1);
			timeInSeconds = Long.valueOf(time);
			timeInSeconds *= 3600;
		} else if (time.endsWith("mn")) {
			time = time.substring(0, time.length() - 2);
			timeInSeconds = Long.valueOf(time);
			timeInSeconds *= 60;
		} else
			timeInSeconds = Long.valueOf(time);

		// TODO Auto-generated method stub
		return timeInSeconds;
	}

	public static Object get(Binding binding, String expression) {
		GroovyShell shell = new GroovyShell(binding);

		Object value = shell.evaluate(expression);

		return value;

	}

	public static Object getObject(String expression) {
		Binding binding = new Binding();

		return get(binding, expression);
	}

}
